print("File to initialize the vending machine:")
file = input()
with open(file, 'r') as f:
    lines = f.readlines()
destinations = []
tickets_fare = []
for line in lines[1:]:
    destination = line.strip('\n').split()[0]
    ticket_fare = int(line.strip('\n').split()[1])
    destinations.append(destination)
    tickets_fare.append(ticket_fare)
print('Station(s): '+', '.join(destinations)+'.')
while True:
    choice = input('Please choose a destination or enter \'Exit\':')
    for i in range(len(destinations)):
        if choice == destinations[i]:
            inserted = 0
            coins = []
            while True:
                print('Destination: %s, ' % destinations[i]+'Price: $%d, ' % tickets_fare[i] + 'Inserted: $%d.' % inserted)
                coin = input('Please insert a coin or enter \'Cancel\':')
                if coin == 'Cancel':
                    print('Cancelled. Returned coin(s): '+','.join(sorted(coins)))
                    break
                elif int(coin) not in [1,2,5,10]:
                    continue 
                elif coin.isdigit():
                    coins.append('$'+coin)
                    inserted += int(coin)
                    if inserted >= tickets_fare[i]:
                        print('Dropped ticket. Your change: $%d.' % (inserted-tickets_fare[i]))
                        break
                else:
                    continue
    if choice == 'Exit':
        break
    else:
        continue


